import {Component, Input, OnInit} from '@angular/core';
import {ReferData} from "../../../../model/admin/ReferData";
import {AlertService} from "../../../../services/alert.service";
import {AdminService} from "../../../../services/admin.service";

@Component({
  selector: 'app-referdataedit',
  templateUrl: './referdataedit.component.html',
  styleUrls: ['./referdataedit.component.css']
})
export class ReferdataeditComponent implements OnInit {
  @Input()optype:string;
  @Input()id:string;
  @Input()typeid:string;
  d:ReferData
  constructor(private adminService:AdminService,
              private alertService:AlertService) {
    this.d = new ReferData();
  }

  ngOnInit(): void {
    if(this.optype=='add'){
      this.d=new ReferData();
      this.d.typeid=this.typeid;
    }
    else if(this.optype=='update'){
      this.getReferDataByid();
    }

  }

  getReferDataByid(){
    this.adminService.getReferdatabyid(this.id)
      .then((data:any)=>{
        if(data.msg=='ok'){
          this.d=new ReferData();
          this.d=data.obj;
        }
        else {
          this.alertService.showError('获取参考数据异常，请重试');
        }
      })
  }

  save(){
    this.adminService.saveReferdata(this.d)
      .then((data:any)=>{
        if(data.msg=='ok'){

        }
        else {
          this.alertService.showError('保存参考数据异常，请重试');
          // this.modal.close('error');
        }
      })
  }

}
